<!--  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Execution programs for the Stock Quoter Publisher/Subscriber Real-time CORBA Service</title>
</head>

<body
 text = "#000000"
 link = "#000fff"
 vLink= "#ff0f0f"
 aLink = "#0000ff"
 bgColor = "#ffffff">

<hr><h2>Execution programs for the Stock Quoter Publisher/Subscriber Real-time CORBA Service</h2><hr>

<P> There are three execution programs (*.cpp files that have the main () functions) in this system:
Distributor, Broker and Admin. Each of them belongs to the corresponding project defined in the
StockQuoter.mpc file. <P>

<h3>Building the Distributor program</h3>

The Distributor.cpp file is used for this purpose. It contains the main () function and is used to generated the
Distributor execution file. The main steps in this file are described as follows: <P>

<li>Initialize the ORB.</li> <P>

<li>Parse the command-line arguments, which give the stock distributor notification rate and the stock database
update rate.<P>

<li>Get the RootPOA.</li> <P>

<li>Activate the POAManager.</li> <P>

<li>Create a StockDistributor factory object, which will then create a StockDistributor object.</li>
<PRE>
    Stock_StockDistributorHome_i stock_distributor_home (orb.in ());
    Stock::StockDistributor_var stock_distributor = stock_distributor_home.create ();
</PRE>

<li>Register the StockDistributor servant with the Naming Service or write the object reference of the
StockDistributor object to a file such that other projects can read it when they are bootstrapping.</li> <P>

<li>Set the initial notification rate of the StockDistributor object.</li> <P>

<li>Set the database update rate.</li> <P>

<li>Enter into the event looping.</li> <P>

<li>Cleanup the POA and ORB.</li> <P>

<hr><h3>Building the Broker program</h3>

The Broker.cpp file is used for this purpose. It contains the main () function and is used to generated the
Broker execution file. The main steps in this file are described as follows: <P>

<li>Initialize the ORB.</li> <P>

<li>Parse the command-line arguments, which give the stock name and the priority of the StockBroker object
(actually, the priority of the StockNameConsumer object that the StockBroker object contains).</li> <P>

<li>Get the RootPOA.</li> <P>

<li>Activate the POAManager.</li> <P>

<li>Create a StockBroker factory object, which will then create a StockBroker object.</li>
<PRE>
    Stock_StockBrokerHome_i stock_broker_home (orb, stock_name, priority);
    Stock::StockBroker_var stock_broker = stock_broker_home.create ();
</PRE>

<li>Read and destringify the StockDistributor object's IOR or use Naming Service to get the object reference
and narrow it to a StockDistributor object reference.</li> <P>

<li>Create a StockBroker factory object and use it to create a StockBroker object.</li>
<PRE>
    Stock_StockBrokerHome_i stock_broker_home (orb.in ());
    Stock::StockBroker_var stock_broker = stock_broker_home.create (stock_distributor.in (), stock_name.c_str ());
</PRE>

<li>Create a new consumer; initialize it; subscribe it with the Stock Distributor server.</li>
<PRE>
    Stock::StockNameConsumer_var consumer = stock_broker->get_consumer_notifier ();
    Stock::Cookie_var cookie = stock_distributor->subscribe_notifier (consumer, priority_level);
    consumer->cookie (cookie.in ());
</PRE>

<li>Set the cookie attribute of the consumer.</li>
<PRE>
    consumer->cookie (cookie.in ());
</PRE>

<li>Get the object reference to a StockQuoter that's been activated at the appropriate priority.</li>
<PRE>
    Stock::StockQuoter_var stock_quoter = stock_distributor->provide_quoter_info (cookie.in ());
</PRE>

<li>Stash the StockQuoter object reference away for later use.</li>
<PRE>
    stock_broker->connect_quoter_info (stock_quoter);
</PRE>

<li>Enter into the event looping.</li> <P>

<li>Cleanup the POA and ORB.</li> <P>

<hr><h3>Building the Admin program</h3>

The Admin.cpp file is used for this purpose. It contains the main () function and is used to generated
Admin execution file. The main steps in this file are described as follows: <P>

<li>Initialize the ORB.</li> <P>

<li>Parse the command-line arguments, which give the option of different operations of StockDistributor interface.</li> <P>

<li>Read and destringify the StockDistributor object's IOR or use Naming Service to get the object reference
and narrow it to a StockDistributor object reference.</li> <P>

<li>Call the operations of StockDistributor interface:</li>
<PRE>
    start: Start the distributor.
    stop: Stop the distributor.
    rate: Change the notification rate of the distributor.
</PRE>

<li>Cleanup the ORB.</li> <P>

<hr><h3>Running the Stock Quoter Service</h3>

When executing the programs, they should be executed in the following order:

<PRE>
    Distributor
    Broker
    Admin
</PRE>

You can run more than one Broker program at the same time. Each of them should be given different stock name
that it is interested in. All the stock information is installed in the <A HREF="database.html">Stock Database</A>.
The number of stocks can easily be extended by adding items to the stock_names array of
the Stock Database constuctor. <P>

<hr><b>Email: </b><a href="mailto:"</a<ADDRESS>shanshan.jiang@vanderbilt.edu</ADDRESS>

</body>

</html>
